package com.javajun.custom;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;

public class DataGridParam {

    private Integer page;
    private Integer rows;
    private String sort;
    private String order;
    
    public Pageable buildPageable() {
        if(sort==null) {
            return PageRequest.of(page-1, rows);
        }else {
            return PageRequest.of(page-1, rows, Direction.fromString(order), sort);
        }
    }
    
    public Integer getPage() {
        return page;
    }
    public void setPage(Integer page) {
        this.page = page;
    }
    public Integer getRows() {
        return rows;
    }
    public void setRows(Integer rows) {
        this.rows = rows;
    }
    public String getSort() {
        return sort;
    }
    public void setSort(String sort) {
        this.sort = sort;
    }
    public String getOrder() {
        return order;
    }
    public void setOrder(String order) {
        this.order = order;
    }
    
}
